// JavaScript Document
jQuery(function($) {
    $('.btn-change-status').on('click',function(){
		var status = $(this).attr('status');
		//var controller = $(this).parents('table').attr('controller');
		var page = $(this).parents('table').attr('page');
		var key = $(this).parents('tr').attr('rel');
		var selector = $(this);
		selector.parents('tr').find('td.status small').empty().append('<img src="'+baseURL+'images/progress.gif"  alt=""/>');
		$.ajax({
			type: "POST",
			url: 'change_status' + ((page!=undefined)?'_'+page:''),
			dataType: 'json',
			data: {key: key, status: status},
			success: function(result){
				//var result = $.parseJSON(data);
				if(result.success){
					selector.attr('status',result.status);
					if(result.status == 1){
						selector.find('i').attr('class','icon-ok-sign');
						selector.parents('tr').find('td.status small').empty().append('<span class="label label-success">Hoạt động</span>');
					}else
						if(result.status == 2){
							selector.find('i').attr('class','icon-remove-sign');
							selector.parents('tr').find('td.status small').empty().append('<span class="label">Không hoạt động</span>');
						}
				}
			}
		});
		return false;
	});
});